﻿using Autofac;
using FreeSql.DataAnnotations;
using DBContext;
using System;
using CommunityToolkit.Mvvm.ComponentModel;


namespace ZoneLine.Models
{
    public class ParaInfoModel : ObservableObject
    {
        [Column(IsIdentity = true)]
        public int Id { get; set; }

        private string _plcIp;
        /// <summary>
        /// PLCIp
        /// </summary>
        public string PlcIp
        {
            get { return _plcIp; }
            set => SetProperty(ref _plcIp, value);
        }

        private int _plcPort;
        /// <summary>
        /// PLC端口
        /// </summary>
        public int PlcPort
        {
            get { return _plcPort; }
            set => SetProperty(ref _plcPort, value);
        }

        private string _eslServer;

        /// <summary>
        /// nasurl
        /// </summary>
        public string EslServer
        {
            get { return _eslServer; }
            set => SetProperty(ref _eslServer, value);
        }

        private string _storeCode;

        public string StoreCode
        {
            get { return _storeCode; }
            set => SetProperty(ref _storeCode, value);
        }


        private string _key;

        public string Key
        {
            get { return _key; }
            set => SetProperty(ref _key, value);
        }

        private string _apiUrl;
        /// <summary>
        /// 系统api
        /// </summary>
        public string ApiUrl
        {
            get { return _apiUrl; }
            set => SetProperty(ref _apiUrl, value);
        }

        private bool _enableScanToOpen;

        public bool EnableScanToOpen
        {
            get { return _enableScanToOpen; }
            set => SetProperty(ref _enableScanToOpen, value);
        }



        private static ParaInfoModel _paraInfo;

        public static ParaInfoModel GetPara()
        {
            if (_paraInfo == null)
            {
                var dal = ContainerServer.Container.Resolve<IModelDAL>();
                var paraInfo = dal.GetModel<ParaInfoModel>(p => true);
                if (paraInfo == null)
                {
                    throw new Exception("db info is empty");
                }
                _paraInfo = paraInfo;
                return paraInfo;
            }
            else
            {
                return _paraInfo;
            }
        }
    }
}
